use std::cmp::Ordering;
use std::io;

fn main() {
    println!("Welcome to Guessing Game");
    let secret_num = rand::random_range(1..101);
    let mut guess = String::new();
    loop {
        guess.clear();
        println!("Please input your guess.");
        io::stdin()
            .read_line(&mut guess)
            .expect("Failed to read line");
        let guess = match guess.trim().parse::<u32>() {
            Ok(num) => num,
            Err(_) => {
                println!("Please type a number!");
                continue;
            }
        };
        println!("You guess: {guess}");
        match guess.cmp(&secret_num) {
            Ordering::Less => {
                println!("Too small");
            }
            Ordering::Equal => {
                println!("You win");
                break;
            }
            Ordering::Greater => {
                println!("Too big");
            }
        }
    }
}
